/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.skin.bezel.util;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Arc2D;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;


/**
 * TODO make this configurable: gradient colors, level of translucency
 * 
 * @author Peter De Bruycker
 */
public class BezelBackgroundPainter extends SoftClipPainter {
    @Override
    protected Shape getClip(JComponent component) {
        return new RoundRectangle2D.Float(0, 0, component.getWidth(), component.getHeight(), 40, 40);
    }

    @Override
    protected void doPaint(Graphics2D graphics, JComponent component) {
        int width = component.getWidth();
        int height = component.getHeight();

        // top gradient
        Color topGradientColor1 = new Color(65, 62, 75);
        Color topGradientColor2 = new Color(111, 103, 129);
        GradientPaint topGradient = new GradientPaint(0.0f, 0, topGradientColor1, 0.0f, height / 2.0f,
                topGradientColor2);
        graphics.setPaint(topGradient);
        graphics.fillRect(0, 0, width, height / 2);

        // bottom gradient
        Color bottomGradientColor1 = new Color(79, 69, 98);
        Color bottomGradientColor2 = new Color(136, 121, 165);
        GradientPaint bottomGradient = new GradientPaint(0.0f, height / 2.0f, bottomGradientColor1, 0.0f, height * 2,
                bottomGradientColor2);
        graphics.setPaint(bottomGradient);

        Arc2D.Double arc = new Arc2D.Double(0 - width / 2, height / 3, width * 2, height * 2, 0, 180, Arc2D.PIE);
        graphics.fill(arc);
    }

    @Override
    protected void doPaint(Graphics2D graphics, BufferedImage image, int x, int y) {
        graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, 0.85f));
        super.doPaint(graphics, image, x, y);
    }
}